<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Locking and non-Berkeley DB applications</title>
    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
    <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" />
    <link rel="up" href="lock.html" title="Chapter 15.  The Locking Subsystem" />
    <link rel="prev" href="lock_am_conv.html" title="Berkeley DB Transactional Data Store locking conventions" />
    <link rel="next" href="log.html" title="Chapter 16.  The Logging Subsystem" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">Locking and non-Berkeley DB applications</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="lock_am_conv.html">Prev</a> </td>
          <th width="60%" align="center">Chapter 15. 
		The Locking Subsystem
        </th>
          <td width="20%" align="right"> <a accesskey="n" href="log.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="sect1" lang="en" xml:lang="en">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both"><a id="lock_nondb"></a>Locking and non-Berkeley DB applications</h2>
          </div>
        </div>
      </div>
      <p>The Lock subsystem is useful outside the context of Berkeley DB.  It can be
used to manage concurrent access to any collection of either ephemeral
or persistent objects.  That is, the lock region can persist across
invocations of an application, so it can be used to provide long-term
locking (for example, conference room scheduling).</p>
      <p>In order to use the locking subsystem in such a general way, the
applications must adhere to a convention for identifying objects and
lockers.  Consider a conference room scheduling problem, in which there
are three conference rooms scheduled in half-hour intervals. The
scheduling application must then select a way to identify each
conference room/time slot combination.  In this case, we could describe
the objects being locked as bytestrings consisting of the conference
room name, the date when it is needed, and the beginning of the
appropriate half-hour slot.</p>
      <p>Lockers are 32-bit numbers, so we might choose to use the User ID of
the individual running the scheduling program.  To schedule half-hour
slots, all the application needs to do is issue a <a href="../api_reference/C/lockget.html" class="olink">DB_ENV-&gt;lock_get()</a> call
for the appropriate locker/object pair.  To schedule a longer slot, the
application needs to issue a <a href="../api_reference/C/lockvec.html" class="olink">DB_ENV-&gt;lock_vec()</a> call, with one
<a href="../api_reference/C/lockget.html" class="olink">DB_ENV-&gt;lock_get()</a> operation per half-hour — up to the total length.  If
the <a href="../api_reference/C/lockvec.html" class="olink">DB_ENV-&gt;lock_vec()</a> call fails, the application would have to release
the parts of the time slot that were obtained.</p>
      <p>To cancel a reservation, the application would make the appropriate
<a href="../api_reference/C/lockput.html" class="olink">DB_ENV-&gt;lock_put()</a> calls.  To reschedule a reservation, the
<a href="../api_reference/C/lockget.html" class="olink">DB_ENV-&gt;lock_get()</a> and <a href="../api_reference/C/lockput.html" class="olink">DB_ENV-&gt;lock_put()</a> calls could all be made inside of
a single <a href="../api_reference/C/lockvec.html" class="olink">DB_ENV-&gt;lock_vec()</a> call. The output of <a href="../api_reference/C/lockstat.html" class="olink">DB_ENV-&gt;lock_stat()</a> could
be post-processed into a human-readable schedule of conference room
use.</p>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="lock_am_conv.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="lock.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="log.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">Berkeley DB Transactional Data Store locking conventions </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> Chapter 16. 
		The Logging Subsystem
        </td>
        </tr>
      </table>
    </div>
  </body>
</html>
